/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Tbv_vehiculosDAOImpl implements orm.dao.Tbv_vehiculosDAO {
	public Tbv_vehiculos loadTbv_vehiculosByORMID(int ve_id_vehiculo) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_vehiculosByORMID(session, ve_id_vehiculo);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_vehiculos getTbv_vehiculosByORMID(int ve_id_vehiculo) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_vehiculosByORMID(session, ve_id_vehiculo);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_vehiculos loadTbv_vehiculosByORMID(int ve_id_vehiculo, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_vehiculosByORMID(session, ve_id_vehiculo, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_vehiculos getTbv_vehiculosByORMID(int ve_id_vehiculo, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_vehiculosByORMID(session, ve_id_vehiculo, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_vehiculos loadTbv_vehiculosByORMID(PersistentSession session, int ve_id_vehiculo) throws PersistentException {
		try {
			return (Tbv_vehiculos) session.load(orm.Tbv_vehiculos.class, new Integer(ve_id_vehiculo));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_vehiculos getTbv_vehiculosByORMID(PersistentSession session, int ve_id_vehiculo) throws PersistentException {
		try {
			return (Tbv_vehiculos) session.get(orm.Tbv_vehiculos.class, new Integer(ve_id_vehiculo));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_vehiculos loadTbv_vehiculosByORMID(PersistentSession session, int ve_id_vehiculo, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_vehiculos) session.load(orm.Tbv_vehiculos.class, new Integer(ve_id_vehiculo), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_vehiculos getTbv_vehiculosByORMID(PersistentSession session, int ve_id_vehiculo, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_vehiculos) session.get(orm.Tbv_vehiculos.class, new Integer(ve_id_vehiculo), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_vehiculos[] listTbv_vehiculosByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_vehiculosByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_vehiculos[] listTbv_vehiculosByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_vehiculosByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_vehiculos[] listTbv_vehiculosByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_vehiculos as Tbv_vehiculos");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Tbv_vehiculos[]) list.toArray(new Tbv_vehiculos[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_vehiculos[] listTbv_vehiculosByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_vehiculos as Tbv_vehiculos");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Tbv_vehiculos[]) list.toArray(new Tbv_vehiculos[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_vehiculos loadTbv_vehiculosByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_vehiculosByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_vehiculos loadTbv_vehiculosByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_vehiculosByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_vehiculos loadTbv_vehiculosByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Tbv_vehiculos[] tbv_vehiculoses = listTbv_vehiculosByQuery(session, condition, orderBy);
		if (tbv_vehiculoses != null && tbv_vehiculoses.length > 0)
			return tbv_vehiculoses[0];
		else
			return null;
	}
	
	public Tbv_vehiculos loadTbv_vehiculosByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Tbv_vehiculos[] tbv_vehiculoses = listTbv_vehiculosByQuery(session, condition, orderBy, lockMode);
		if (tbv_vehiculoses != null && tbv_vehiculoses.length > 0)
			return tbv_vehiculoses[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTbv_vehiculosByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_vehiculosByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_vehiculosByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_vehiculosByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_vehiculosByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_vehiculos as Tbv_vehiculos");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_vehiculosByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_vehiculos as Tbv_vehiculos");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_vehiculos createTbv_vehiculos() {
		return new orm.Tbv_vehiculos();
	}
	
	public boolean save(orm.Tbv_vehiculos tbv_vehiculos) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().saveObject(tbv_vehiculos);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Tbv_vehiculos tbv_vehiculos) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().deleteObject(tbv_vehiculos);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_vehiculos tbv_vehiculos)throws PersistentException {
		try {
			orm.Tbv_ruta[] lTbv_rutas = tbv_vehiculos.tbv_ruta.toArray();
			for(int i = 0; i < lTbv_rutas.length; i++) {
				lTbv_rutas[i].setTbv_vehiculosve_id_vehiculo(null);
			}
			return delete(tbv_vehiculos);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_vehiculos tbv_vehiculos, org.orm.PersistentSession session)throws PersistentException {
		try {
			orm.Tbv_ruta[] lTbv_rutas = tbv_vehiculos.tbv_ruta.toArray();
			for(int i = 0; i < lTbv_rutas.length; i++) {
				lTbv_rutas[i].setTbv_vehiculosve_id_vehiculo(null);
			}
			try {
				session.delete(tbv_vehiculos);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Tbv_vehiculos tbv_vehiculos) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().refresh(tbv_vehiculos);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Tbv_vehiculos tbv_vehiculos) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().evict(tbv_vehiculos);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_vehiculos loadTbv_vehiculosByCriteria(Tbv_vehiculosCriteria tbv_vehiculosCriteria) {
		Tbv_vehiculos[] tbv_vehiculoses = listTbv_vehiculosByCriteria(tbv_vehiculosCriteria);
		if(tbv_vehiculoses == null || tbv_vehiculoses.length == 0) {
			return null;
		}
		return tbv_vehiculoses[0];
	}
	
	public Tbv_vehiculos[] listTbv_vehiculosByCriteria(Tbv_vehiculosCriteria tbv_vehiculosCriteria) {
		return tbv_vehiculosCriteria.listTbv_vehiculos();
	}
}
